package org.kjtc.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.kjtc.security.MySecurityMetadataSource;
import org.kjtc.util.Const;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class LogOutController extends BaseController {

	@Resource(name = "mySecurityMetadataSource")
	private MySecurityMetadataSource mySecurityMetadataSource;

	@SuppressWarnings("static-access")
	@RequestMapping(value = "logOut")
	@ResponseBody
	public Map<String, Object> logOut() {

		Map<String, Object> map = new HashMap<String, Object>();
		logger.info(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "系统退出");
		try {
//			this.getSession().invalidate();
			this.getSession().removeAttribute(Const.SESSION_USER);
			mySecurityMetadataSource.resourceMap = null;
			SecurityContextHolder.getContext().setAuthentication(null);
			map.put("result", "Success");
			logger.info("系统退出成功");
		} catch (Exception e) {
			e.printStackTrace();
			map.put("result", "Error");
			logger.error(this.getUesrInfo().getUserName() + "(" + this.getUesrInfo().getUserID() + ")：" + "系统退出异常：" + e.getMessage());
		}
		return map;
	}
}
